package gamagora.game.utils
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Shader;
	import flash.display.ShaderJob;
	import flash.utils.ByteArray;
	
	import gamagora.game.utils.OSImages;
	
	import org.flixel.FlxSprite;

	public class OSSunShader
	{
		private var _outputImage:FlxSprite;
		private var _shader:Shader;
		
		public function OSSunShader()
		{
			_shader = new Shader(new OSImages.LIGHT_SHADER() as ByteArray);
			var inputImageData:BitmapData = (new OSImages.BG() as Bitmap).bitmapData;
			_shader.data.src.input = inputImageData;
			
			//Paramètres
			_shader.data.center.value = [inputImageData.width / 2, 100];
			_shader.data.attenuationDelta.value = [175]; // Taille externe
			_shader.data.attenuationSpeed.value = [1.0]; // Taille interne
			_shader.data.attenuationDecay.value = [1.0]; // Puissance de la lumière
			
			var outputImageData:BitmapData = new BitmapData(inputImageData.width, inputImageData.height);
			var shaderJob:ShaderJob = new ShaderJob(_shader, outputImageData);
			shaderJob.start(true);
			
			_outputImage = new FlxSprite();
			_outputImage.pixels = outputImageData;
			_outputImage.scrollFactor.x = 0;
		}
		
		public function update():void
		{
			
		}
		
		public function draw():void
		{
			_outputImage.draw();
		}
		
		public function destroy():void
		{
			_outputImage.destroy();
		}
		
	}
}
